# -*- coding: utf-8 -*-


class IMEI():

    @staticmethod
    def is_valid(imei):
        if not imei.isalnum():
            return False
        length = len(imei)
        return 14 <= length <= 17

    @staticmethod
    def is_checksum_ok(imei):
        if not imei.isdigit():
            return False
        elif len(imei) < 15:
            return False

        checksum = 0
        do_double = False
        for c in imei[:14]:
            val = int(c)
            if do_double:
                val *= 2
            checksum += val % 10
            checksum += int(val / 10)
            do_double = not do_double
        checksum += int(imei[14])

        return checksum % 10 == 0
